<html>
  <header>
      <meta charset="utf-8">
    <title></title>
    <link rel="stylesheet" href="../css/register.css">
  </header>
  <body>
   <div class="box">
      <h1>注册</h1>
      <div class="form"><input id="email" class="login_input" type="text" name="" value="" placeholder="请输入您的邮箱"></div>
      <div class="form"><input id="studentId" class="login_input" type="text" name="" value="" placeholder="请输入您的学号 选填项"></div>
      <div class="form"><input id="name" class="login_input" type="text" name="" value="" placeholder="请输入昵称"></div>
      <div class="form"><input id="password" class="login_input" type="" name="" value="" placeholder="请输入您的密码"></div>
      <div class="form"><input id="repassword" class="login_input" type="" name="" value="" placeholder="请再输入一次您的密码"></div>
      <div class="form"><button type="button" name="button" onclick="register()">注册</button></div>
      <div class="form"><a href="login.html">已有账号，立即登录</a></div>

   </div>
  </body>
  <script type="text/javascript" src="../script/api.js"></script>
  <script type="text/javascript" src="../script/jquery.js"></script>
  <script type="text/javascript" src="../script/main.js"></script>
  <script type="text/javascript">
    function register(){
      console.log(api.deviceId);
      var email = $("#email").val();
      var studentId = $("#studentId").val();
      var name = $("#name").val();
      var password = $("#password").val();
      var repassword = $("#repassword").val();
      var emailReg=/^[a-z0-9]+([._\\-]*[a-z0-9])*@([a-z0-9]+[-a-z0-9]*[a-z0-9]+.){1,63}[a-z0-9]+$/;
      var common = 'http://113.17.111.241:9999';
      if (name == "") {
             toast("昵称为空！","bottom");
      }
      if(email != "" && emailReg.test(email)){
         if(password == "" || repassword == ""){
             toast("密码不能为空！","bottom");
         }
         else{
           if(password == repassword){
             console.log(email);
             console.log(password);
             console.log(name);
            var deviceId = api.deviceId;
             $.ajax({
                 url:common + '/universityfacade/api/paAdmin/newPaAdmin?email='+email+'&pwd='+password+'&nickname='+name,
                method: 'POST',
                 headers: {
                   "Access-Control-Allow-Origin": "*",
                   "Access-Control-Allow-Headers": "Authorization",
                   "Content-Type" : 'application/json; charset=utf-8'
                 },
                 data:{"nickname":name},
                 success:function(json){
                     api.alert({ msg:'注册成功'});
                 },
                 error:function(json){
                   toast("邮箱已被注册！","bottom");
                 }
             })


           }
           else{
               toast("两次密码不一致！","bottom");
           }
         }
        }
      else{
        toast("邮箱格式有误！","bottom");
      }
    }
  </script>
</html>
